* GSS analysis for: 
* Unions, Class Identification and Policy Attitudes
* Date: 03/31/22


*******************************************************************************
***** IRT analysis.
*******************************************************************************


set seed 112233

* IRT model for latent objective class.
irt grm inc5 edu5 egp5rev
estimates store m_irt1
predict objcls1, latent

* With year dummies.
qui tab year, gen(year_)

irt grm inc5 edu5 egp5rev year_2-year_32
estimates store m_irt2
predict objcls2, latent

* Additive index.
* Standardize variables.
foreach v of varlist inc5 edu5 egp5rev {
	egen `v'_z = std(`v')
}

gen objcls3 = (inc5_z + edu5_z + egp5rev_z) / 3


corr objcls2 objcls1 objcls3


hist objcls1
cluster kmeans objcls1, k(5) gen(clust1) start(random(10))
table clust1, c(min objcls1 max objcls1)

recode clust1 (5 = 1 "Lower class") (3 = 2 "Working class") (1 = 3 "Lower middle class") (4 = 4 "Upper middle class") (2 = 5 "Upper class"), gen(objcls5_b)


hist objcls2
cluster kmeans objcls2, k(5) gen(clust2) start(random(10))
table clust2, c(min objcls2 max objcls2)

recode clust2 (5 = 1 "Lower class") (3 = 2 "Working class") (1 = 3 "Lower middle class") (4 = 4 "Upper middle class") (2 = 5 "Upper class"), gen(objcls5)

kap objcls5 objcls5_b



* Save data for descriptive tables and plotting.
save GSS_SubClass_clean.dta, replace

